package com.woniu.liuzhougov.common.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @author zhuxinpan
 * @version 1.0
 * @className ValidatedResult
 * @description 用来返回校验结果
 * @date 2019/4/26 16:31
 */
public class ValidatedResult {
    /**
     * @param tip
     * @param bindingResult
     * @return java.lang.String
     * @author zhuxinpan
     * @date 2019/4/26 16:34
     * @description 获取验证失败的信息
     */
    public static String getValidateMessage(String tip, BindingResult bindingResult) {
        StringBuffer stringBuffer = new StringBuffer(tip);
        List<FieldError> fieldErrors = bindingResult.getFieldErrors();
        fieldErrors.forEach(fieldError -> {
            stringBuffer.append("<br>" + fieldError.getDefaultMessage());
        });
        return stringBuffer.toString();
    }
}
